package com.xuexiang.xuidemo.page.text;

import ohos.agp.components.Button;
import ohos.agp.components.Component;

import com.xuexiang.xui_lib.component.textview.marqueen.LogText;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;

/**
 * AutoFitText 自适应字体大小的文字
 *
 * @since 2021-04-06
 */
@Page(name = "LoggerTextView", subTitle = "日志打印工具", action = "LoggerTextAbilitySlice", ability = TextAbility.class)
public class LoggerTextAbilitySlice extends BasePageAbilitySlice implements Component.ClickedListener {
    private Button normal;
    private Button sucess;
    private Button error;
    private Button warning;
    private Button clear;
    private LogText logger;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_log_text;
    }

    @Override
    protected void onActive() {
        super.onActive();
        findView();
    }

    private void findView() {
        normal = findCastComponentById(ResourceTable.Id_bt_normal);
        sucess = findCastComponentById(ResourceTable.Id_bt_sucess);
        error = findCastComponentById(ResourceTable.Id_bt_error);
        warning = findCastComponentById(ResourceTable.Id_bt_warning);
        clear = findCastComponentById(ResourceTable.Id_bt_clear);
        logger = findCastComponentById(ResourceTable.Id_log_text);

        normal.setClickedListener(this);
        sucess.setClickedListener(this);
        error.setClickedListener(this);
        warning.setClickedListener(this);
        clear.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_bt_normal:
                logger.logNormal("这是一条普通日志！");
                break;
            case ResourceTable.Id_bt_sucess:
                logger.logSuccess("这是一条成功日志！");
                break;
            case ResourceTable.Id_bt_error:
                logger.logError("这是一条出错日志！");
                break;
            case ResourceTable.Id_bt_warning:
                logger.logWarning("这是一条警告日志！");
                break;
            case ResourceTable.Id_bt_clear:
                logger.clearLog();
                break;
            default:
                break;
        }
    }
}
